Parameters
- arguments
Library/Library.Test/TestCmdInterpreter.cs
C# | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.Get | DefaultCommands.Set | DefaultCommands.Help, DefaultCommands.Default); TestCommands cmds = new TestCommands(); CommandInterpreter ci = new CommandInterpreter(cmds); cmds.OtherData = 42; Assert.AreEqual("42", Capture(ci, "GET Other")); cmds.SomeData = "one-two-three"; Assert.AreEqual("one-two-three", Capture(ci, "GET SomeData")); string options = Capture(ci, "SET"); cmds.OtherData = 0; cmds.SomeData = String.Empty; Assert.AreEqual("0", Capture(ci, "GET Other")); Assert.AreEqual(String.Empty, Capture(ci, "GET SomeData")); TextReader input = Console.In; try { Console.SetIn(new StringReader(options));//feed the output of SET back to SET ci.Run("SET", "/readInput"); } finally { Console.SetIn(input); } //should now be restored Assert.AreEqual("42", Capture(ci, "GET Other")); Assert.AreEqual("one-two-three", Capture(ci, "GET SomeData")); |
VB.NET | Copy Code |
---|---|
Assert.AreEqual(DefaultCommands.[Get] Or DefaultCommands.[Set] Or DefaultCommands.Help, DefaultCommands.[Default]) Dim cmds As New TestCommands() Dim ci As New CommandInterpreter(cmds) cmds.OtherData = 42 Assert.AreEqual("42", Capture(ci, "GET Other")) cmds.SomeData = "one-two-three" Assert.AreEqual("one-two-three", Capture(ci, "GET SomeData")) Dim options As String = Capture(ci, "SET") cmds.OtherData = 0 cmds.SomeData = [String].Empty Assert.AreEqual("0", Capture(ci, "GET Other")) Assert.AreEqual([String].Empty, Capture(ci, "GET SomeData")) Dim input As TextReader = Console.[In] Try Console.SetIn(New StringReader(options)) 'feed the output of SET back to SET ci.Run("SET", "/readInput") Finally Console.SetIn(input) End Try 'should now be restored Assert.AreEqual("42", Capture(ci, "GET Other")) Assert.AreEqual("one-two-three", Capture(ci, "GET SomeData")) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7